package org.cid54.bukkit;

import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityListener;
import org.cid54.bukkit.model.AquamanRegister;

/**
 *
 * @author fgo
 */
public class Cid54AquamanListener extends EntityListener {
    
    private AquamanRegister register = AquamanRegister.instance;
    
    @Override
    public void onEntityDamage(EntityDamageEvent event) {
        
        if (event.getEntity() instanceof Player) {
            
            if (event.getCause().equals(EntityDamageEvent.DamageCause.DROWNING)) {
                
                Player p = (Player) event.getEntity();
                
                if (this.register.isPlayerAquaman(p)) {
                    
                    p.setRemainingAir(p.getMaximumAir());
                    p.setHealth(20);
                    p.setHealth(20);
                    
                }
                
            }
            
        }
        
    }
}
